import vue from '@vitejs/plugin-vue';
// import styleImport from 'vite-plugin-style-import';
const { resolve } = require('path');
import { defineConfig } from 'vite';
import viteCompression from 'vite-plugin-compression';
import Components from 'unplugin-vue-components/vite';
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers';
export default defineConfig({
  base: '/',
  resolve: {
    alias: [{ find: '@', replacement: resolve(__dirname, 'src') }],
  },
  server: {
    // proxy: {
    //   '/api': {
    //     target: 'xxxx',
    //     changeOrigin: true,
    //     rewrite: path => path.replace(/^\/api/, '/'),
    //   },
    // },
  },
  build: {
    assetsDir: './static',
    chunkSizeWarningLimit: 1500,
    rollupOptions: {
      output: {
        manualChunks(id) {
          if (id.includes('node_modules')) {
            return id.toString().split('node_modules/')[1].split('/')[0].toString();
          }
        },
      },
    },
    terserOptions: {
      compress: {
        // warnings: false,
        drop_console: true,
        drop_debugger: true,
        pure_funcs: ['console.log'],
      },
      output: {
        // 去掉注释内容
        comments: true,
      },
    },
    brotliSize: false,
  },
  cssPreprocessOptions: {
    scss: {
      additionalData: '@import "./src/assets/css/index.scss";', // 添加公共样式
    },
  },
  plugins: [
    vue(),
    viteCompression(),
    Components({
      resolvers: [ElementPlusResolver()],
    }),
    // styleImport({
    //   libs: [
    //     {
    //       libraryName: 'element-plus',
    //       esModule: true,
    //       ensureStyleFile: true,
    //       resolveStyle: name => {
    //         name = name.slice(3);
    //         return `element-plus/packages/theme-chalk/src/${name}.scss`;
    //       },
    //       resolveComponent: name => {
    //         return `element-plus/lib/${name}`;
    //       },
    //     },
    //   ],
    // }),
  ],
});
